$(function () {
    //加载表格数据
    methods.getTableData();
});

var data = {
    //页面对话框
    dialog: {
        show: false,
        loading: false,
        disabled: false,
        title: "信息"
    },
    //分页
    paging: {
        currentPage: 1,
        pageSize: 10,
        total: 11,
        tableData: []
    },
    //搜索
    sContent: "",
    //当前对象
    currentObj: {
        status: "1"
    },
    expandRow: []
};

var methods = {
    //添加子菜单
    addSubMenu: function (row) {
        data.currentObj.parentId = row.id;
        data.dialog.title = "【" + row.name + "】添加子菜单";
        data.dialog.show = true;
    },
    //更新菜单
    updateMenu: function (row) {
        data.currentObj = JSON.parse(JSON.stringify(row));
        data.dialog.title = "修改【" + row.name + "】菜单";
        data.dialog.show = true;
    },//删除菜单
    deleteMenu: function (row) {
        layer.confirm("您确定要删除【" + row.name + "】菜单吗？", function (index) {
            layer.close(index);
            ajax.post("/system/menu/deleteMenu", {id: row.id}, function (res) {
                layer.msg(res.msg);
                methods.getTableData();
            })
        })
    },
    //添加或保存
    saveOrUpdate: function () {
        data.dialog.loading = true;
        data.currentObj.children = null;
        ajax.post("/system/menu/saveOrUpdateMenu", data.currentObj, function (res) {
            data.dialog.loading = false;
            if (res.code == 1) {
                layer.msg(res.msg);
                data.dialog.show = false;
                methods.getTableData();
            } else {
                layer.alert(res.msg);
            }
        });
    },
    //搜索菜单
    searchMenu: function () {
        data.paging.currentPage = 1;
        methods.getTableData();
    },
    //获取表格数据
    getTableData: function () {
        var load = layer.load(2);
        ajax.post("/system/menu/getMenuPagingData", {
            sContent: data.sContent,
            currentPage: data.paging.currentPage,
            pageSize: data.paging.pageSize
        }, function (res) {
            layer.close(load);
            data.paging.total = res.data.total;
            data.paging.tableData = res.data.rows;
        })
    },
    //处理页面大小变化
    handleSizeChange: function (val) {
        data.paging.pageSize = val;
        data.paging.currentPage = 1;
        methods.getTableData();
    },
    //处理当前页面变化
    handleCurrentChange: function (val) {
        data.paging.currentPage = val;
        methods.getTableData();
    },
    //处理对话框关闭
    handleDialogClose: function () {
        data.dialog.loading = false;
        data.dialog.disabled = false;
        data.dialog.title = "信息";
        data.currentObj = {
            status: "1"
        };
    }

};
var vm = new Vue({data: data, methods: methods}).$mount("#app");
